package com.xbj.cloud.controller;

import com.xbj.cloud.commons.resp.ResultData;
import com.xbj.cloud.db.pojo.Pay;
import com.xbj.cloud.service.PayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 观雾
 * @create: 2024-08-26
 * @description:
 **/
@RestController
@Tag(name = "熔断/舱壁测试模块",description = "熔断/舱壁测试类")
public class PayCircuitController {
    private static final Logger LOG = LoggerFactory.getLogger(PayCircuitController.class);
    @Resource
    private PayService payService;


    @GetMapping(value = "/payCircuit/getById/{id}")
    @Operation(summary = "熔断测试方法",description = "-1:抛异常,-2:超时,其余正常")
    public ResultData payCircuitGetById(@PathVariable("id") Integer id){
        LOG.info("熔断测试方法,id:"+id);
        if (id == -1){
            throw  new RuntimeException("参数不能为负数");
        }
        if(id == -2){
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        Pay pay = payService.getById(id);
        ResultData resultData = ResultData.success(pay);
        return  resultData;
    }

    @GetMapping(value = "/payBulkhead/getById/{id}")
    @Operation(summary = "舱壁测试方法",description = "-1:抛异常,-2:超时,其余正常")
    public ResultData payBulkheadGetById(@PathVariable("id") Integer id){
        LOG.info("舱壁测试方法,id:"+id);
        if (id == -1){
            throw  new RuntimeException("参数不能为负数");
        }
        if(id == -2){
            try {
                Thread.sleep(8000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        Pay pay = payService.getById(id);
        ResultData resultData = ResultData.success(pay);
        return  resultData;
    }
}
